package com.jeecg.p3.divination.service.impl;

import com.jeecg.p3.divination.dao.WxActDivinationRecordDao;
import com.jeecg.p3.divination.entity.WxActDivinationRecord;
import com.jeecg.p3.divination.service.WxActDivinationRecordService;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("wxActDivinationRecordService")
public class WxActDivinationRecordServiceImpl implements WxActDivinationRecordService {
	@Resource
	private WxActDivinationRecordDao wxActDivinationRecordDao;

	@Override
	public void doAdd(WxActDivinationRecord wxActDivinationRecord) {
		wxActDivinationRecordDao.insert(wxActDivinationRecord);
	}

	@Override
	public void doEdit(WxActDivinationRecord wxActDivinationRecord) {
		wxActDivinationRecordDao.update(wxActDivinationRecord);
	}

	@Override
	public void doDelete(String id) {
		wxActDivinationRecordDao.delete(id);
	}

	@Override
	public WxActDivinationRecord queryById(String id) {
		WxActDivinationRecord wxActDivinationRecord  = wxActDivinationRecordDao.get(id);
		return wxActDivinationRecord;
	}

	@Override
	public PageList<WxActDivinationRecord> queryPageList(
		PageQuery<WxActDivinationRecord> pageQuery) {
		PageList<WxActDivinationRecord> result = new PageList<WxActDivinationRecord>();
		Integer itemCount = wxActDivinationRecordDao.count(pageQuery);
		PageQueryWrapper<WxActDivinationRecord> wrapper = new PageQueryWrapper<>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
		List<WxActDivinationRecord> list = wxActDivinationRecordDao.queryPageList(wrapper);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}
	@Override
	public List<WxActDivinationRecord> queryBargainRecordListByOpenidAndActidAndJwid(
			String openid, String actId, String jwid, Date currDate) {
		if(currDate==null){
			return wxActDivinationRecordDao.queryBargainRecordListByOpenidAndActidAndJwid(openid, actId, jwid);
		}
		return wxActDivinationRecordDao.queryBargainRecordListByOpenidAndActidAndJwidAndCurdate(openid, actId, jwid,currDate);
	}

	@Override
	public List<WxActDivinationRecord> queryscoreList(
			 String actId) {
		
		return wxActDivinationRecordDao.queryscoreList(actId);
	}

	@Override
	public List<WxActDivinationRecord> queryExportExcel(String actId) {
		return wxActDivinationRecordDao.queryExportExcel(actId);
	}

	@Override
	public Integer queryCountByOpenidAndActId(String actId, String openid) {
		return wxActDivinationRecordDao.queryCountByOpenidAndActId(actId, openid);
	}

	@Override
	public Integer queryCountByOpenidAndActIdPerDay(String actId,String openid, String date) {
		return wxActDivinationRecordDao.queryCountByOpenidAndActIdPerDay(actId, openid, date);
	}
	//update-begin--Author:zhangweijian  Date: 20180308 for：摇签活动的参与总人数和平均值查询
	//获取当前活动的参与总人数
	@Override
	public String getAccountsByactId(String actId) {
		return wxActDivinationRecordDao.getAccountsByactId(actId);
	}

	//获取当前活动的分数平均值
	@Override
	public String getAveByactId(String actId) {
		return wxActDivinationRecordDao.getAveByactId(actId);
	}
	//update-end--Author:zhangweijian  Date: 20180308 for：摇签活动的参与总人数和平均值查询
}
